package com.liruo.learn.spring.security.resphandler;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author:liruo
 * @Date:2023-05-26-19:57:22
 * @Desc
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ResponseStatus(code = HttpStatus.ACCEPTED)
    @ExceptionHandler(Some2XXException.class)
    public BaseResp<String> some2XX(Some2XXException err){
        log.info("",err);
        return BaseResp.fail(err.getMessage(), 20001);
    }
    @ResponseStatus(code = HttpStatus.INTERNAL_SERVER_ERROR)
    @ExceptionHandler(BusinessException.class)
    public BaseResp<String> business(BusinessException err){
        return BaseResp.fail(err.getMessage(), 50001);
    }

    @ResponseStatus(code = HttpStatus.INTERNAL_SERVER_ERROR)
    @ExceptionHandler(Throwable.class)
    public BaseResp<String> business(Throwable err){
        return BaseResp.fail(err.getMessage(), 50000);
    }
}
